package com.example.aspects;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
//@Aspect
@Order(3)
public class LoginAspect {


    //提取切入点表达式
    @Pointcut("execution(* com.example.day02.*.*(..))")
    public  void  declarePointCut(){};

    /**
     * 通知--规定切面应该做的事情
     * 切入点表达式--作用：规定了该通知被应用的位置
     *
     */

    //前置通知
    @Before(" declarePointCut()")
    public  void testbefore(JoinPoint joinPoint){
        System.out.println("日志before-》"+joinPoint.getSignature().getName()+"参数："+ Arrays.toString(joinPoint.getArgs()));
    }

    //后置通知
    @After(" declarePointCut()")
    public  void testafter(JoinPoint joinPoint){
        System.out.println("日志after-》"+joinPoint.getSignature().getName()+"参数："+ Arrays.toString(joinPoint.getArgs()));
    }

    //后置返回通知
    @AfterReturning(value = " declarePointCut()",returning = "result")
    public  void    testafterReturning(JoinPoint joinPoint, Object result){
        System.out.println("日志返回通知：：==》result："+result);
    }

    //异常--只有异常的时候才会执行---记录下来这个异常
    @AfterThrowing(value = " declarePointCut()",throwing ="e" )
    public  void testAfterThrowing(JoinPoint joinPoint,Throwable e){
        System.out.println("日志出现了异常。。。。。。："+e);
    }


}
